package com.ruoyi.wechat.service.impl;

import com.ruoyi.common.constant.GaoDeConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.wechat.domain.WeChatConfig;
import com.ruoyi.wechat.mapper.WechatConfigMapper;
import com.ruoyi.wechat.service.WeChatConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

import static com.ruoyi.common.constant.GaoDeConstants.GAO_DE_KEY;
import static com.ruoyi.wechat.constants.WeChatConstants.*;

/**
 * @author zyj
 * @date 2022-08-23 12:32
 */
@Service
public class WeChatConfigServiceImpl implements WeChatConfigService {


    @Autowired
    private WechatConfigMapper wechatConfigMapper;

    @Autowired
    private RedisCache redisCache;

    @PostConstruct
    public void init(){
        WeChatConfig weChatConfig = wechatConfigMapper.selectWechatConfig();
        redisCache.setCacheObject(WECHAT_APP_ID_KEY,weChatConfig.getAppId());
        redisCache.setCacheObject(WECHAT_APP_SECRET_KAY,weChatConfig.getAppSecret());
        redisCache.setCacheObject(GAO_DE_KEY,weChatConfig.getGdKey());
    }
}
